package com.example.jinbo.helloword;

/**
 * Created by JinBo on 2015/12/17.
 */

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Description:
 * <br/>website: <a href="http://www.crazyit.org">crazyit.org</a>
 * <br/>Copyright (C), 2001-2014, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 *
 * @author Yeeku.H.Lee kongyeeku@163.com
 * @version 1.0
 */
public class DetailFragment extends Fragment {
    public static final String ITEM_ID = "item_id";
    private int mNum=-2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 如果启动该Fragment时包含了ITEM_ID参数
        //getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);//放在这里也是可以的
        if (getArguments().containsKey(ITEM_ID)) {
            mNum = getArguments().getInt(ITEM_ID); //①
        }
    }

    // 重写该方法，该方法返回的View将作为Fragment显示的组件
    @Override
    public View onCreateView(LayoutInflater inflater
            , ViewGroup container, Bundle savedInstanceState) {
        // 加载/res/layout/目录下的fragment_book_detail.xml布局文件
        View rootView = inflater.inflate(R.layout.fragment_detail,
                container, false);
        if (mNum!=-2) {
            // 让book_title文本框显示book对象的title属性
            if(mNum==-1)
            {
                ((TextView) rootView.findViewById(R.id.detail))
                        .setText("我是主页面");
                getActivity().getActionBar().setTitle("HelloWord");
            }
            else
            ((TextView) rootView.findViewById(R.id.detail))
                    .setText("我是详细页面"+(mNum+1));
        }
        return rootView;
    }
}

